macro_rules! magic_number {
    ($name:ident, $value:expr) => {
        const $name: u32 = $value;
    };
}
magic_number!(KEYC_MASK_FLAGS, 0xff000000);

extern "C" {
    pub type event_base;
    pub type evbuffer;
    pub type bufferevent_ops;
    pub type args;
    pub type tmuxpeer;
    pub type hyperlinks;
    pub type screen_write_cline;
    pub type screen_sel;
    pub type screen_titles;
    pub type environ;
    pub type options;
    pub type format_tree;
    pub type input_ctx;
    pub type cmds;
    pub type tty_key;
    pub type tty_code;
    pub type format_job_tree;
    pub type control_state;
    pub type cmdq_list;
    pub type cmdq_item;
    pub type cmdq_state;
    fn free(_: *mut ());
    fn strcmp(_: *const i8, _: *const i8) -> i32;
    fn xmalloc(_: size_t) -> *mut ();
    fn xcalloc(_: size_t, _: size_t) -> *mut ();
    fn xstrdup(_: *const i8) -> *mut i8;
    fn cmd_list_free(_: *mut cmd_list);
    fn cmd_list_print(_: *mut cmd_list, _: i32) -> *mut i8;
    fn cmd_list_all_have(_: *mut cmd_list, _: i32) -> i32;
    fn cmd_parse_from_string(_: *const i8, _: *mut cmd_parse_input) -> *mut cmd_parse_result;
    fn cmdq_new_state(_: *mut cmd_find_state, _: *mut key_event, _: i32) -> *mut cmdq_state;
    fn cmdq_free_state(_: *mut cmdq_state);
    fn cmdq_get_command(_: *mut cmd_list, _: *mut cmdq_state) -> *mut cmdq_item;
    fn cmdq_get_callback1(_: *const i8, _: cmdq_cb, _: *mut ()) -> *mut cmdq_item;
    fn cmdq_insert_after(_: *mut cmdq_item, _: *mut cmdq_item) -> *mut cmdq_item;
    fn cmdq_append(_: *mut client, _: *mut cmdq_item) -> *mut cmdq_item;
    fn cmdq_error(_: *mut cmdq_item, _: *const i8, _: ...);
    fn key_string_lookup_key(_: key_code, _: i32) -> *const i8;
    fn server_client_set_key_table(_: *mut client, _: *const i8);
    static mut clients: clients;
    fn log_debug(_: *const i8, _: ...);
    fn fatalx(_: *const i8, _: ...) -> !;
}
pub type __u_char = u8;
pub type __u_short = u16;
pub type __u_int = u32;
pub type __uint8_t = u8;
pub type __uint64_t = u64;
pub type __pid_t = i32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_short = __u_short;
pub type u_int = __u_int;
pub type pid_t = __pid_t;
pub type time_t = __time_t;
pub type size_t = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type cc_t = u8;
pub type speed_t = u32;
pub type tcflag_t = u32;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_line: cc_t,
    pub c_cc: [cc_t; 32],
    pub c_ispeed: speed_t,
    pub c_ospeed: speed_t,
}
pub type uint8_t = __uint8_t;
pub type uint64_t = __uint64_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event {
    pub ev_evcallback: event_callback,
    pub ev_timeout_pos: C2RustUnnamed_4,
    pub ev_fd: i32,
    pub ev_base: *mut event_base,
    pub ev_: C2RustUnnamed,
    pub ev_events: i16,
    pub ev_res: i16,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed {
    pub ev_io: C2RustUnnamed_2,
    pub ev_signal: C2RustUnnamed_0,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub ev_signal_next: C2RustUnnamed_1,
    pub ev_ncalls: i16,
    pub ev_pncalls: *mut i16,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
    pub ev_io_next: C2RustUnnamed_3,
    pub ev_timeout: timeval,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_3 {
    pub le_next: *mut event,
    pub le_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_4 {
    pub ev_next_with_common_timeout: C2RustUnnamed_5,
    pub min_heap_idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_5 {
    pub tqe_next: *mut event,
    pub tqe_prev: *mut *mut event,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_callback {
    pub evcb_active_next: C2RustUnnamed_7,
    pub evcb_flags: i16,
    pub evcb_pri: uint8_t,
    pub evcb_closure: uint8_t,
    pub evcb_cb_union: C2RustUnnamed_6,
    pub evcb_arg: *mut (),
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_6 {
    pub evcb_callback: Option<unsafe extern "C" fn(i32, i16, *mut ()) -> ()>,
    pub evcb_selfcb: Option<unsafe extern "C" fn(*mut event_callback, *mut ()) -> ()>,
    pub evcb_evfinalize: Option<unsafe extern "C" fn(*mut event, *mut ()) -> ()>,
    pub evcb_cbfinalize: Option<unsafe extern "C" fn(*mut event_callback, *mut ()) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_7 {
    pub tqe_next: *mut event_callback,
    pub tqe_prev: *mut *mut event_callback,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct bufferevent {
    pub ev_base: *mut event_base,
    pub be_ops: *const bufferevent_ops,
    pub ev_read: event,
    pub ev_write: event,
    pub input: *mut evbuffer,
    pub output: *mut evbuffer,
    pub wm_read: event_watermark,
    pub wm_write: event_watermark,
    pub readcb: bufferevent_data_cb,
    pub writecb: bufferevent_data_cb,
    pub errorcb: bufferevent_event_cb,
    pub cbarg: *mut (),
    pub timeout_read: timeval,
    pub timeout_write: timeval,
    pub enabled: i16,
}
pub type bufferevent_event_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, i16, *mut ()) -> ()>;
pub type bufferevent_data_cb =
    Option<unsafe extern "C" fn(*mut bufferevent, *mut ()) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct event_watermark {
    pub low: size_t,
    pub high: size_t,
}
pub type bitstr_t = u8;
pub type msgtype = u32;
pub const MSG_READ_CANCEL: msgtype = 307;
pub const MSG_WRITE_CLOSE: msgtype = 306;
pub const MSG_WRITE_READY: msgtype = 305;
pub const MSG_WRITE: msgtype = 304;
pub const MSG_WRITE_OPEN: msgtype = 303;
pub const MSG_READ_DONE: msgtype = 302;
pub const MSG_READ: msgtype = 301;
pub const MSG_READ_OPEN: msgtype = 300;
pub const MSG_FLAGS: msgtype = 218;
pub const MSG_EXEC: msgtype = 217;
pub const MSG_WAKEUP: msgtype = 216;
pub const MSG_UNLOCK: msgtype = 215;
pub const MSG_SUSPEND: msgtype = 214;
pub const MSG_OLDSTDOUT: msgtype = 213;
pub const MSG_OLDSTDIN: msgtype = 212;
pub const MSG_OLDSTDERR: msgtype = 211;
pub const MSG_SHUTDOWN: msgtype = 210;
pub const MSG_SHELL: msgtype = 209;
pub const MSG_RESIZE: msgtype = 208;
pub const MSG_READY: msgtype = 207;
pub const MSG_LOCK: msgtype = 206;
pub const MSG_EXITING: msgtype = 205;
pub const MSG_EXITED: msgtype = 204;
pub const MSG_EXIT: msgtype = 203;
pub const MSG_DETACHKILL: msgtype = 202;
pub const MSG_DETACH: msgtype = 201;
pub const MSG_COMMAND: msgtype = 200;
pub const MSG_IDENTIFY_TERMINFO: msgtype = 112;
pub const MSG_IDENTIFY_LONGFLAGS: msgtype = 111;
pub const MSG_IDENTIFY_STDOUT: msgtype = 110;
pub const MSG_IDENTIFY_FEATURES: msgtype = 109;
pub const MSG_IDENTIFY_CWD: msgtype = 108;
pub const MSG_IDENTIFY_CLIENTPID: msgtype = 107;
pub const MSG_IDENTIFY_DONE: msgtype = 106;
pub const MSG_IDENTIFY_ENVIRON: msgtype = 105;
pub const MSG_IDENTIFY_STDIN: msgtype = 104;
pub const MSG_IDENTIFY_OLDCWD: msgtype = 103;
pub const MSG_IDENTIFY_TTYNAME: msgtype = 102;
pub const MSG_IDENTIFY_TERM: msgtype = 101;
pub const MSG_IDENTIFY_FLAGS: msgtype = 100;
pub const MSG_VERSION: msgtype = 12;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client {
    pub name: *const i8,
    pub peer: *mut tmuxpeer,
    pub queue: *mut cmdq_list,
    pub windows: client_windows,
    pub control_state: *mut control_state,
    pub pause_age: u_int,
    pub pid: pid_t,
    pub fd: i32,
    pub out_fd: i32,
    pub event: event,
    pub retval: i32,
    pub creation_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub environ: *mut environ,
    pub jobs: *mut format_job_tree,
    pub title: *mut i8,
    pub path: *mut i8,
    pub cwd: *const i8,
    pub term_name: *mut i8,
    pub term_features: i32,
    pub term_type: *mut i8,
    pub term_caps: *mut *mut i8,
    pub term_ncaps: u_int,
    pub ttyname: *mut i8,
    pub tty: tty,
    pub written: size_t,
    pub discarded: size_t,
    pub redraw: size_t,
    pub repeat_timer: event,
    pub click_timer: event,
    pub click_button: u_int,
    pub click_event: mouse_event,
    pub status: status_line,
    pub flags: uint64_t,
    pub exit_type: C2RustUnnamed_30,
    pub exit_msgtype: msgtype,
    pub exit_session: *mut i8,
    pub exit_message: *mut i8,
    pub keytable: *mut key_table,
    pub last_key: key_code,
    pub redraw_panes: uint64_t,
    pub redraw_scrollbars: uint64_t,
    pub message_ignore_keys: i32,
    pub message_ignore_styles: i32,
    pub message_string: *mut i8,
    pub message_timer: event,
    pub prompt_string: *mut i8,
    pub prompt_buffer: *mut utf8_data,
    pub prompt_last: *mut i8,
    pub prompt_index: size_t,
    pub prompt_inputcb: prompt_input_cb,
    pub prompt_freecb: prompt_free_cb,
    pub prompt_data: *mut (),
    pub prompt_hindex: [u_int; 4],
    pub prompt_mode: C2RustUnnamed_27,
    pub prompt_saved: *mut utf8_data,
    pub prompt_flags: i32,
    pub prompt_type: prompt_type,
    pub prompt_cursor: i32,
    pub session: *mut session,
    pub last_session: *mut session,
    pub references: i32,
    pub pan_window: *mut (),
    pub pan_ox: u_int,
    pub pan_oy: u_int,
    pub overlay_check: overlay_check_cb,
    pub overlay_mode: overlay_mode_cb,
    pub overlay_draw: overlay_draw_cb,
    pub overlay_key: overlay_key_cb,
    pub overlay_free: overlay_free_cb,
    pub overlay_resize: overlay_resize_cb,
    pub overlay_data: *mut (),
    pub overlay_timer: event,
    pub files: client_files,
    pub clipboard_panes: *mut u_int,
    pub clipboard_npanes: u_int,
    pub entry: C2RustUnnamed_8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_8 {
    pub tqe_next: *mut client,
    pub tqe_prev: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_files {
    pub rbh_root: *mut client_file,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_file {
    pub c: *mut client,
    pub peer: *mut tmuxpeer,
    pub tree: *mut client_files,
    pub references: i32,
    pub stream: i32,
    pub path: *mut i8,
    pub buffer: *mut evbuffer,
    pub event: *mut bufferevent,
    pub fd: i32,
    pub error: i32,
    pub closed: i32,
    pub cb: client_file_cb,
    pub data: *mut (),
    pub entry: C2RustUnnamed_9,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_9 {
    pub rbe_left: *mut client_file,
    pub rbe_right: *mut client_file,
    pub rbe_parent: *mut client_file,
    pub rbe_color: i32,
}
pub type client_file_cb = Option<
    unsafe extern "C" fn(*mut client, *const i8, i32, i32, *mut evbuffer, *mut ()) -> (),
>;
pub type overlay_resize_cb = Option<unsafe extern "C" fn(*mut client, *mut ()) -> ()>;
pub type overlay_free_cb = Option<unsafe extern "C" fn(*mut client, *mut ()) -> ()>;
pub type overlay_key_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *mut key_event) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_event {
    pub key: key_code,
    pub m: mouse_event,
    pub buf: *mut i8,
    pub len: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct mouse_event {
    pub valid: i32,
    pub ignore: i32,
    pub key: key_code,
    pub statusat: i32,
    pub statuslines: u_int,
    pub x: u_int,
    pub y: u_int,
    pub b: u_int,
    pub lx: u_int,
    pub ly: u_int,
    pub lb: u_int,
    pub ox: u_int,
    pub oy: u_int,
    pub s: i32,
    pub w: i32,
    pub wp: i32,
    pub sgr_type: u_int,
    pub sgr_b: u_int,
}
pub type key_code = u64;
pub type overlay_draw_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *mut screen_redraw_ctx) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen_redraw_ctx {
    pub c: *mut client,
    pub statuslines: u_int,
    pub statustop: i32,
    pub pane_status: i32,
    pub pane_lines: pane_lines,
    pub pane_scrollbars: i32,
    pub pane_scrollbars_pos: i32,
    pub no_pane_gc: grid_cell,
    pub no_pane_gc_set: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub ox: u_int,
    pub oy: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_cell {
    pub data: utf8_data,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
pub type pane_lines = u32;
pub const PANE_LINES_NUMBER: pane_lines = 4;
pub const PANE_LINES_SIMPLE: pane_lines = 3;
pub const PANE_LINES_HEAVY: pane_lines = 2;
pub const PANE_LINES_DOUBLE: pane_lines = 1;
pub const PANE_LINES_SINGLE: pane_lines = 0;
pub type overlay_mode_cb = Option<
    unsafe extern "C" fn(*mut client, *mut (), *mut u_int, *mut u_int) -> *mut screen,
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct screen {
    pub title: *mut i8,
    pub path: *mut i8,
    pub titles: *mut screen_titles,
    pub grid: *mut grid,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub default_cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub default_ccolour: i32,
    pub rupper: u_int,
    pub rlower: u_int,
    pub mode: i32,
    pub default_mode: i32,
    pub saved_cx: u_int,
    pub saved_cy: u_int,
    pub saved_grid: *mut grid,
    pub saved_cell: grid_cell,
    pub saved_flags: i32,
    pub tabs: *mut bitstr_t,
    pub sel: *mut screen_sel,
    pub write_list: *mut screen_write_cline,
    pub hyperlinks: *mut hyperlinks,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid {
    pub flags: i32,
    pub sx: u_int,
    pub sy: u_int,
    pub hscrolled: u_int,
    pub hsize: u_int,
    pub hlimit: u_int,
    pub linedata: *mut grid_line,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct grid_line {
    pub celldata: *mut grid_cell_entry,
    pub cellused: u_int,
    pub cellsize: u_int,
    pub extddata: *mut grid_extd_entry,
    pub extdsize: u_int,
    pub flags: i32,
    pub time: time_t,
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_extd_entry {
    pub data: utf8_char,
    pub attr: u_short,
    pub flags: u_char,
    pub fg: i32,
    pub bg: i32,
    pub us: i32,
    pub link: u_int,
}
pub type utf8_char = u_int;
#[derive(Copy, Clone)]
#[repr(C, packed)]
pub struct grid_cell_entry {
    pub c2rust_unnamed: C2RustUnnamed_10,
    pub flags: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub union C2RustUnnamed_10 {
    pub offset: u_int,
    pub data: C2RustUnnamed_11,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_11 {
    pub attr: u_char,
    pub fg: u_char,
    pub bg: u_char,
    pub data: u_char,
}
pub type screen_cursor_style = u32;
pub const SCREEN_CURSOR_BAR: screen_cursor_style = 3;
pub const SCREEN_CURSOR_UNDERLINE: screen_cursor_style = 2;
pub const SCREEN_CURSOR_BLOCK: screen_cursor_style = 1;
pub const SCREEN_CURSOR_DEFAULT: screen_cursor_style = 0;
pub type overlay_check_cb = Option<
    unsafe extern "C" fn(
        *mut client,
        *mut (),
        u_int,
        u_int,
        u_int,
        *mut overlay_ranges,
    ) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct overlay_ranges {
    pub px: [u_int; 3],
    pub nx: [u_int; 3],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct session {
    pub id: u_int,
    pub name: *mut i8,
    pub cwd: *const i8,
    pub creation_time: timeval,
    pub last_attached_time: timeval,
    pub activity_time: timeval,
    pub last_activity_time: timeval,
    pub lock_timer: event,
    pub curw: *mut winlink,
    pub lastw: winlink_stack,
    pub windows: winlinks,
    pub statusat: i32,
    pub statuslines: u_int,
    pub options: *mut options,
    pub flags: i32,
    pub attached: u_int,
    pub tio: *mut termios,
    pub environ: *mut environ,
    pub references: i32,
    pub gentry: C2RustUnnamed_13,
    pub entry: C2RustUnnamed_12,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_12 {
    pub rbe_left: *mut session,
    pub rbe_right: *mut session,
    pub rbe_parent: *mut session,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_13 {
    pub tqe_next: *mut session,
    pub tqe_prev: *mut *mut session,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlinks {
    pub rbh_root: *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink {
    pub idx: i32,
    pub session: *mut session,
    pub window: *mut window,
    pub flags: i32,
    pub entry: C2RustUnnamed_16,
    pub wentry: C2RustUnnamed_15,
    pub sentry: C2RustUnnamed_14,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_14 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_15 {
    pub tqe_next: *mut winlink,
    pub tqe_prev: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_16 {
    pub rbe_left: *mut winlink,
    pub rbe_right: *mut winlink,
    pub rbe_parent: *mut winlink,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window {
    pub id: u_int,
    pub latest: *mut (),
    pub name: *mut i8,
    pub name_event: event,
    pub name_time: timeval,
    pub alerts_timer: event,
    pub offset_timer: event,
    pub activity_time: timeval,
    pub active: *mut window_pane,
    pub last_panes: window_panes,
    pub panes: window_panes,
    pub lastlayout: i32,
    pub layout_root: *mut layout_cell,
    pub saved_layout_root: *mut layout_cell,
    pub old_layout: *mut i8,
    pub sx: u_int,
    pub sy: u_int,
    pub manual_sx: u_int,
    pub manual_sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub new_sx: u_int,
    pub new_sy: u_int,
    pub new_xpixel: u_int,
    pub new_ypixel: u_int,
    pub fill_character: *mut utf8_data,
    pub flags: i32,
    pub alerts_queued: i32,
    pub alerts_entry: C2RustUnnamed_19,
    pub options: *mut options,
    pub references: u_int,
    pub winlinks: C2RustUnnamed_18,
    pub entry: C2RustUnnamed_17,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_17 {
    pub rbe_left: *mut window,
    pub rbe_right: *mut window,
    pub rbe_parent: *mut window,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_18 {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_19 {
    pub tqe_next: *mut window,
    pub tqe_prev: *mut *mut window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cell {
    pub type_0: layout_type,
    pub parent: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub wp: *mut window_pane,
    pub cells: layout_cells,
    pub entry: C2RustUnnamed_20,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_20 {
    pub tqe_next: *mut layout_cell,
    pub tqe_prev: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct layout_cells {
    pub tqh_first: *mut layout_cell,
    pub tqh_last: *mut *mut layout_cell,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane {
    pub id: u_int,
    pub active_point: u_int,
    pub window: *mut window,
    pub options: *mut options,
    pub layout_cell: *mut layout_cell,
    pub saved_layout_cell: *mut layout_cell,
    pub sx: u_int,
    pub sy: u_int,
    pub xoff: u_int,
    pub yoff: u_int,
    pub flags: i32,
    pub sb_slider_y: u_int,
    pub sb_slider_h: u_int,
    pub argc: i32,
    pub argv: *mut *mut i8,
    pub shell: *mut i8,
    pub cwd: *mut i8,
    pub pid: pid_t,
    pub tty: [i8; 32],
    pub status: i32,
    pub dead_time: timeval,
    pub fd: i32,
    pub event: *mut bufferevent,
    pub offset: window_pane_offset,
    pub base_offset: size_t,
    pub resize_queue: window_pane_resizes,
    pub resize_timer: event,
    pub ictx: *mut input_ctx,
    pub cached_gc: grid_cell,
    pub cached_active_gc: grid_cell,
    pub palette: colour_palette,
    pub pipe_fd: i32,
    pub pipe_event: *mut bufferevent,
    pub pipe_offset: window_pane_offset,
    pub screen: *mut screen,
    pub base: screen,
    pub status_screen: screen,
    pub status_size: size_t,
    pub modes: C2RustUnnamed_24,
    pub searchstr: *mut i8,
    pub searchregex: i32,
    pub border_gc_set: i32,
    pub border_gc: grid_cell,
    pub control_bg: i32,
    pub control_fg: i32,
    pub scrollbar_style: style,
    pub entry: C2RustUnnamed_23,
    pub sentry: C2RustUnnamed_22,
    pub tree_entry: C2RustUnnamed_21,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_21 {
    pub rbe_left: *mut window_pane,
    pub rbe_right: *mut window_pane,
    pub rbe_parent: *mut window_pane,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_22 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_23 {
    pub tqe_next: *mut window_pane,
    pub tqe_prev: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style {
    pub gc: grid_cell,
    pub ignore: i32,
    pub fill: i32,
    pub align: style_align,
    pub list: style_list,
    pub range_type: style_range_type,
    pub range_argument: u_int,
    pub range_string: [i8; 16],
    pub width: i32,
    pub pad: i32,
    pub default_type: style_default_type,
}
pub type style_default_type = u32;
pub const STYLE_DEFAULT_POP: style_default_type = 2;
pub const STYLE_DEFAULT_PUSH: style_default_type = 1;
pub const STYLE_DEFAULT_BASE: style_default_type = 0;
pub type style_range_type = u32;
pub const STYLE_RANGE_USER: style_range_type = 6;
pub const STYLE_RANGE_SESSION: style_range_type = 5;
pub const STYLE_RANGE_WINDOW: style_range_type = 4;
pub const STYLE_RANGE_PANE: style_range_type = 3;
pub const STYLE_RANGE_RIGHT: style_range_type = 2;
pub const STYLE_RANGE_LEFT: style_range_type = 1;
pub const STYLE_RANGE_NONE: style_range_type = 0;
pub type style_list = u32;
pub const STYLE_LIST_RIGHT_MARKER: style_list = 4;
pub const STYLE_LIST_LEFT_MARKER: style_list = 3;
pub const STYLE_LIST_FOCUS: style_list = 2;
pub const STYLE_LIST_ON: style_list = 1;
pub const STYLE_LIST_OFF: style_list = 0;
pub type style_align = u32;
pub const STYLE_ALIGN_ABSOLUTE_CENTRE: style_align = 4;
pub const STYLE_ALIGN_RIGHT: style_align = 3;
pub const STYLE_ALIGN_CENTRE: style_align = 2;
pub const STYLE_ALIGN_LEFT: style_align = 1;
pub const STYLE_ALIGN_DEFAULT: style_align = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_24 {
    pub tqh_first: *mut window_mode_entry,
    pub tqh_last: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode_entry {
    pub wp: *mut window_pane,
    pub swp: *mut window_pane,
    pub mode: *const window_mode,
    pub data: *mut (),
    pub screen: *mut screen,
    pub prefix: u_int,
    pub entry: C2RustUnnamed_25,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_25 {
    pub tqe_next: *mut window_mode_entry,
    pub tqe_prev: *mut *mut window_mode_entry,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_mode {
    pub name: *const i8,
    pub default_format: *const i8,
    pub init: Option<
        unsafe extern "C" fn(*mut window_mode_entry, *mut cmd_find_state, *mut args) -> *mut screen,
    >,
    pub free: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub resize: Option<unsafe extern "C" fn(*mut window_mode_entry, u_int, u_int) -> ()>,
    pub update: Option<unsafe extern "C" fn(*mut window_mode_entry) -> ()>,
    pub key: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            key_code,
            *mut mouse_event,
        ) -> (),
    >,
    pub key_table: Option<unsafe extern "C" fn(*mut window_mode_entry) -> *const i8>,
    pub command: Option<
        unsafe extern "C" fn(
            *mut window_mode_entry,
            *mut client,
            *mut session,
            *mut winlink,
            *mut args,
            *mut mouse_event,
        ) -> (),
    >,
    pub formats: Option<unsafe extern "C" fn(*mut window_mode_entry, *mut format_tree) -> ()>,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_find_state {
    pub flags: i32,
    pub current: *mut cmd_find_state,
    pub s: *mut session,
    pub wl: *mut winlink,
    pub w: *mut window,
    pub wp: *mut window_pane,
    pub idx: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_offset {
    pub used: size_t,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct colour_palette {
    pub fg: i32,
    pub bg: i32,
    pub palette: *mut i32,
    pub default_palette: *mut i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resizes {
    pub tqh_first: *mut window_pane_resize,
    pub tqh_last: *mut *mut window_pane_resize,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_pane_resize {
    pub sx: u_int,
    pub sy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub entry: C2RustUnnamed_26,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_26 {
    pub tqe_next: *mut window_pane_resize,
    pub tqe_prev: *mut *mut window_pane_resize,
}
pub type layout_type = u32;
pub const LAYOUT_WINDOWPANE: layout_type = 2;
pub const LAYOUT_TOPBOTTOM: layout_type = 1;
pub const LAYOUT_LEFTRIGHT: layout_type = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct window_panes {
    pub tqh_first: *mut window_pane,
    pub tqh_last: *mut *mut window_pane,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct winlink_stack {
    pub tqh_first: *mut winlink,
    pub tqh_last: *mut *mut winlink,
}
pub type prompt_type = u32;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type C2RustUnnamed_27 = u32;
pub const PROMPT_COMMAND: C2RustUnnamed_27 = 1;
pub const PROMPT_ENTRY: C2RustUnnamed_27 = 0;
pub type prompt_free_cb = Option<unsafe extern "C" fn(*mut ()) -> ()>;
pub type prompt_input_cb =
    Option<unsafe extern "C" fn(*mut client, *mut (), *const i8, i32) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed_28,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_28 {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_29,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_29 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
pub type C2RustUnnamed_30 = u32;
pub const CLIENT_EXIT_DETACH: C2RustUnnamed_30 = 2;
pub const CLIENT_EXIT_SHUTDOWN: C2RustUnnamed_30 = 1;
pub const CLIENT_EXIT_RETURN: C2RustUnnamed_30 = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line {
    pub timer: event,
    pub screen: screen,
    pub active: *mut screen,
    pub references: i32,
    pub style: grid_cell,
    pub entries: [status_line_entry; 5],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct status_line_entry {
    pub expanded: *mut i8,
    pub ranges: style_ranges,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_ranges {
    pub tqh_first: *mut style_range,
    pub tqh_last: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct style_range {
    pub type_0: style_range_type,
    pub argument: u_int,
    pub string: [i8; 16],
    pub start: u_int,
    pub end: u_int,
    pub entry: C2RustUnnamed_31,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_31 {
    pub tqe_next: *mut style_range,
    pub tqe_prev: *mut *mut style_range,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty {
    pub client: *mut client,
    pub start_timer: event,
    pub clipboard_timer: event,
    pub last_requests: time_t,
    pub sx: u_int,
    pub sy: u_int,
    pub xpixel: u_int,
    pub ypixel: u_int,
    pub cx: u_int,
    pub cy: u_int,
    pub cstyle: screen_cursor_style,
    pub ccolour: i32,
    pub oflag: i32,
    pub oox: u_int,
    pub ooy: u_int,
    pub osx: u_int,
    pub osy: u_int,
    pub mode: i32,
    pub fg: i32,
    pub bg: i32,
    pub rlower: u_int,
    pub rupper: u_int,
    pub rleft: u_int,
    pub rright: u_int,
    pub event_in: event,
    pub in_0: *mut evbuffer,
    pub event_out: event,
    pub out: *mut evbuffer,
    pub timer: event,
    pub discarded: size_t,
    pub tio: termios,
    pub cell: grid_cell,
    pub last_cell: grid_cell,
    pub flags: i32,
    pub term: *mut tty_term,
    pub mouse_last_x: u_int,
    pub mouse_last_y: u_int,
    pub mouse_last_b: u_int,
    pub mouse_drag_flag: i32,
    pub mouse_scrolling_flag: i32,
    pub mouse_slider_mpos: i32,
    pub mouse_drag_update: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub mouse_drag_release: Option<unsafe extern "C" fn(*mut client, *mut mouse_event) -> ()>,
    pub key_timer: event,
    pub key_tree: *mut tty_key,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct tty_term {
    pub name: *mut i8,
    pub tty: *mut tty,
    pub features: i32,
    pub acs: [[i8; 2]; 256],
    pub codes: *mut tty_code,
    pub flags: i32,
    pub entry: C2RustUnnamed_32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_32 {
    pub le_next: *mut tty_term,
    pub le_prev: *mut *mut tty_term,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_windows {
    pub rbh_root: *mut client_window,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct client_window {
    pub window: u_int,
    pub pane: *mut window_pane,
    pub sx: u_int,
    pub sy: u_int,
    pub entry: C2RustUnnamed_33,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_33 {
    pub rbe_left: *mut client_window,
    pub rbe_right: *mut client_window,
    pub rbe_parent: *mut client_window,
    pub rbe_color: i32,
}
pub type cmd_retval = i32;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
pub type cmd_parse_status = u32;
pub const CMD_PARSE_SUCCESS: cmd_parse_status = 1;
pub const CMD_PARSE_ERROR: cmd_parse_status = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_result {
    pub status: cmd_parse_status,
    pub cmdlist: *mut cmd_list,
    pub error: *mut i8,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_parse_input {
    pub flags: i32,
    pub file: *const i8,
    pub line: u_int,
    pub item: *mut cmdq_item,
    pub c: *mut client,
    pub fs: cmd_find_state,
}
pub type cmdq_cb = Option<unsafe extern "C" fn(*mut cmdq_item, *mut ()) -> cmd_retval>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct clients {
    pub tqh_first: *mut client,
    pub tqh_last: *mut *mut client,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_tables {
    pub rbh_root: *mut key_table,
}
extern "C" fn key_bindings_RB_MINMAX(
    mut head: *mut key_bindings,
    mut val: i32,
) -> *mut key_binding {
    let mut tmp: *mut key_binding = unsafe { (*head).rbh_root };
    let mut parent: *mut key_binding = std::ptr::null_mut::<key_binding>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else {
            tmp = unsafe { (*tmp).entry.rbe_right };
        }
    }
    return parent;
}
extern "C" fn key_bindings_RB_REMOVE(
    mut head: *mut key_bindings,
    mut elm: *mut key_binding,
) -> *mut key_binding {
    let mut current_block: u64;
    let mut child: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut parent: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut old: *mut key_binding = elm;
    let mut color: i32 = 0;
    if (unsafe { (*elm).entry.rbe_left }).is_null() {
        child = unsafe { (*elm).entry.rbe_right };
        current_block = 7245201122033322888;
    } else if (unsafe { (*elm).entry.rbe_right }).is_null() {
        child = unsafe { (*elm).entry.rbe_left };
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut key_binding = std::ptr::null_mut::<key_binding>();
        elm = unsafe { (*elm).entry.rbe_right };
        loop {
            left = unsafe { (*elm).entry.rbe_left };
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = unsafe { (*elm).entry.rbe_right };
        parent = unsafe { (*elm).entry.rbe_parent };
        color = unsafe { (*elm).entry.rbe_color };
        if !child.is_null() {
            (unsafe { (*child).entry.rbe_parent = parent });
        }
        if !parent.is_null() {
            if (unsafe { (*parent).entry.rbe_left }) == elm {
                (unsafe { (*parent).entry.rbe_left = child });
            } else {
                (unsafe { (*parent).entry.rbe_right = child });
            }
        } else {
            (unsafe { (*head).rbh_root = child });
        }
        if (unsafe { (*elm).entry.rbe_parent }) == old {
            parent = elm;
        }
        (unsafe { (*elm).entry = (*old).entry });
        if !(unsafe { (*old).entry.rbe_parent }).is_null() {
            if (unsafe { (*(*old).entry.rbe_parent).entry.rbe_left }) == old {
                (unsafe { (*(*old).entry.rbe_parent).entry.rbe_left = elm });
            } else {
                (unsafe { (*(*old).entry.rbe_parent).entry.rbe_right = elm });
            }
        } else {
            (unsafe { (*head).rbh_root = elm });
        }
        (unsafe { (*(*old).entry.rbe_left).entry.rbe_parent = elm });
        if !(unsafe { (*old).entry.rbe_right }).is_null() {
            (unsafe { (*(*old).entry.rbe_right).entry.rbe_parent = elm });
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = unsafe { (*left).entry.rbe_parent };
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 7336097146973914068;
    }
    match current_block {
        7245201122033322888 => {
            parent = unsafe { (*elm).entry.rbe_parent };
            color = unsafe { (*elm).entry.rbe_color };
            if !child.is_null() {
                (unsafe { (*child).entry.rbe_parent = parent });
            }
            if !parent.is_null() {
                if (unsafe { (*parent).entry.rbe_left }) == elm {
                    (unsafe { (*parent).entry.rbe_left = child });
                } else {
                    (unsafe { (*parent).entry.rbe_right = child });
                }
            } else {
                (unsafe { (*head).rbh_root = child });
            }
        }
        _ => {}
    }
    if color == 0 {
        key_bindings_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
extern "C" fn key_bindings_RB_REMOVE_COLOR(
    mut head: *mut key_bindings,
    mut parent: *mut key_binding,
    mut elm: *mut key_binding,
) {
    let mut tmp: *mut key_binding = std::ptr::null_mut::<key_binding>();
    while (elm.is_null() || (unsafe { (*elm).entry.rbe_color }) == 0)
        && elm != (unsafe { (*head).rbh_root })
    {
        if (unsafe { (*parent).entry.rbe_left }) == elm {
            tmp = unsafe { (*parent).entry.rbe_right };
            if (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 1 });
                tmp = unsafe { (*parent).entry.rbe_right };
                (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).entry.rbe_right };
            }
            if ((unsafe { (*tmp).entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0
                {
                    let mut oleft: *mut key_binding = std::ptr::null_mut::<key_binding>();
                    oleft = unsafe { (*tmp).entry.rbe_left };
                    if !oleft.is_null() {
                        (unsafe { (*oleft).entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).entry.rbe_color = 1 });
                    oleft = unsafe { (*tmp).entry.rbe_left };
                    (unsafe { (*tmp).entry.rbe_left = (*oleft).entry.rbe_right });
                    if !(unsafe { (*tmp).entry.rbe_left }).is_null() {
                        (unsafe { (*(*oleft).entry.rbe_right).entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oleft).entry.rbe_parent = (*tmp).entry.rbe_parent });
                    if !(unsafe { (*oleft).entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left = oleft });
                        } else {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_right = oleft });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oleft });
                    }
                    (unsafe { (*oleft).entry.rbe_right = tmp });
                    (unsafe { (*tmp).entry.rbe_parent = oleft });
                    let _ = !(unsafe { (*oleft).entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).entry.rbe_right };
                }
                (unsafe { (*tmp).entry.rbe_color = (*parent).entry.rbe_color });
                (unsafe { (*parent).entry.rbe_color = 0 });
                if !(unsafe { (*tmp).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).entry.rbe_right };
                (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        } else {
            tmp = unsafe { (*parent).entry.rbe_left };
            if (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 1 });
                tmp = unsafe { (*parent).entry.rbe_left };
                (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).entry.rbe_left };
            }
            if ((unsafe { (*tmp).entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).entry.rbe_left }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0
                {
                    let mut oright: *mut key_binding = std::ptr::null_mut::<key_binding>();
                    oright = unsafe { (*tmp).entry.rbe_right };
                    if !oright.is_null() {
                        (unsafe { (*oright).entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).entry.rbe_color = 1 });
                    oright = unsafe { (*tmp).entry.rbe_right };
                    (unsafe { (*tmp).entry.rbe_right = (*oright).entry.rbe_left });
                    if !(unsafe { (*tmp).entry.rbe_right }).is_null() {
                        (unsafe { (*(*oright).entry.rbe_left).entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oright).entry.rbe_parent = (*tmp).entry.rbe_parent });
                    if !(unsafe { (*oright).entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left = oright });
                        } else {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_right = oright });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oright });
                    }
                    (unsafe { (*oright).entry.rbe_left = tmp });
                    (unsafe { (*tmp).entry.rbe_parent = oright });
                    let _ = !(unsafe { (*oright).entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).entry.rbe_left };
                }
                (unsafe { (*tmp).entry.rbe_color = (*parent).entry.rbe_color });
                (unsafe { (*parent).entry.rbe_color = 0 });
                if !(unsafe { (*tmp).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).entry.rbe_left };
                (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        }
    }
    if !elm.is_null() {
        (unsafe { (*elm).entry.rbe_color = 0 });
    }
}
extern "C" fn key_bindings_RB_FIND(
    mut head: *mut key_bindings,
    mut elm: *mut key_binding,
) -> *mut key_binding {
    let mut tmp: *mut key_binding = unsafe { (*head).rbh_root };
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = key_bindings_cmp(elm, tmp);
        if comp < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).entry.rbe_right };
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<key_binding>();
}
extern "C" fn key_bindings_RB_NEXT(mut elm: *mut key_binding) -> *mut key_binding {
    if !(unsafe { (*elm).entry.rbe_right }).is_null() {
        elm = unsafe { (*elm).entry.rbe_right };
        while !(unsafe { (*elm).entry.rbe_left }).is_null() {
            elm = unsafe { (*elm).entry.rbe_left };
        }
    } else if !(unsafe { (*elm).entry.rbe_parent }).is_null()
        && elm == (unsafe { (*(*elm).entry.rbe_parent).entry.rbe_left })
    {
        elm = unsafe { (*elm).entry.rbe_parent };
    } else {
        while !(unsafe { (*elm).entry.rbe_parent }).is_null()
            && elm == (unsafe { (*(*elm).entry.rbe_parent).entry.rbe_right })
        {
            elm = unsafe { (*elm).entry.rbe_parent };
        }
        elm = unsafe { (*elm).entry.rbe_parent };
    }
    return elm;
}
extern "C" fn key_bindings_RB_INSERT_COLOR(mut head: *mut key_bindings, mut elm: *mut key_binding) {
    let mut parent: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut gparent: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut tmp: *mut key_binding = std::ptr::null_mut::<key_binding>();
    loop {
        parent = unsafe { (*elm).entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).entry.rbe_parent };
        if parent == (unsafe { (*gparent).entry.rbe_left }) {
            tmp = unsafe { (*gparent).entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).entry.rbe_right };
                    (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                    if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                    if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                        if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                        } else {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).entry.rbe_left = parent });
                    (unsafe { (*parent).entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).entry.rbe_left };
                (unsafe { (*gparent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*gparent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if gparent == (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = gparent });
                (unsafe { (*gparent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).entry.rbe_left };
                    (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                    if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                        (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                    if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                        if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                        } else {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).entry.rbe_right = parent });
                    (unsafe { (*parent).entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).entry.rbe_right };
                (unsafe { (*gparent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*gparent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if gparent == (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = gparent });
                (unsafe { (*gparent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).entry.rbe_color = 0 });
}
extern "C" fn key_bindings_RB_INSERT(
    mut head: *mut key_bindings,
    mut elm: *mut key_binding,
) -> *mut key_binding {
    let mut tmp: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut parent: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = key_bindings_cmp(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).entry.rbe_parent = parent });
    (unsafe { (*elm).entry.rbe_right = std::ptr::null_mut::<key_binding>() });
    (unsafe { (*elm).entry.rbe_left = (*elm).entry.rbe_right });
    (unsafe { (*elm).entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    key_bindings_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<key_binding>();
}
extern "C" fn key_tables_RB_NEXT(mut elm: *mut key_table) -> *mut key_table {
    if !(unsafe { (*elm).entry.rbe_right }).is_null() {
        elm = unsafe { (*elm).entry.rbe_right };
        while !(unsafe { (*elm).entry.rbe_left }).is_null() {
            elm = unsafe { (*elm).entry.rbe_left };
        }
    } else if !(unsafe { (*elm).entry.rbe_parent }).is_null()
        && elm == (unsafe { (*(*elm).entry.rbe_parent).entry.rbe_left })
    {
        elm = unsafe { (*elm).entry.rbe_parent };
    } else {
        while !(unsafe { (*elm).entry.rbe_parent }).is_null()
            && elm == (unsafe { (*(*elm).entry.rbe_parent).entry.rbe_right })
        {
            elm = unsafe { (*elm).entry.rbe_parent };
        }
        elm = unsafe { (*elm).entry.rbe_parent };
    }
    return elm;
}
extern "C" fn key_tables_RB_MINMAX(mut head: *mut key_tables, mut val: i32) -> *mut key_table {
    let mut tmp: *mut key_table = unsafe { (*head).rbh_root };
    let mut parent: *mut key_table = std::ptr::null_mut::<key_table>();
    while !tmp.is_null() {
        parent = tmp;
        if val < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else {
            tmp = unsafe { (*tmp).entry.rbe_right };
        }
    }
    return parent;
}
extern "C" fn key_tables_RB_INSERT(
    mut head: *mut key_tables,
    mut elm: *mut key_table,
) -> *mut key_table {
    let mut tmp: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut parent: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = key_table_cmp(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).entry.rbe_parent = parent });
    (unsafe { (*elm).entry.rbe_right = std::ptr::null_mut::<key_table>() });
    (unsafe { (*elm).entry.rbe_left = (*elm).entry.rbe_right });
    (unsafe { (*elm).entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    key_tables_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<key_table>();
}
extern "C" fn key_tables_RB_INSERT_COLOR(mut head: *mut key_tables, mut elm: *mut key_table) {
    let mut parent: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut gparent: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut tmp: *mut key_table = std::ptr::null_mut::<key_table>();
    loop {
        parent = unsafe { (*elm).entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).entry.rbe_parent };
        if parent == (unsafe { (*gparent).entry.rbe_left }) {
            tmp = unsafe { (*gparent).entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).entry.rbe_right };
                    (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                    if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                    if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                        if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                        } else {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).entry.rbe_left = parent });
                    (unsafe { (*parent).entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).entry.rbe_left };
                (unsafe { (*gparent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*gparent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if gparent == (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = gparent });
                (unsafe { (*gparent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).entry.rbe_left };
                    (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                    if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                        (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                    if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                        if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                        } else {
                            (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).entry.rbe_right = parent });
                    (unsafe { (*parent).entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).entry.rbe_color = 0 });
                (unsafe { (*gparent).entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).entry.rbe_right };
                (unsafe { (*gparent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*gparent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*gparent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if gparent == (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = gparent });
                (unsafe { (*gparent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).entry.rbe_color = 0 });
}
extern "C" fn key_tables_RB_FIND(
    mut head: *mut key_tables,
    mut elm: *mut key_table,
) -> *mut key_table {
    let mut tmp: *mut key_table = unsafe { (*head).rbh_root };
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = key_table_cmp(elm, tmp);
        if comp < 0 {
            tmp = unsafe { (*tmp).entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).entry.rbe_right };
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<key_table>();
}
extern "C" fn key_tables_RB_REMOVE(
    mut head: *mut key_tables,
    mut elm: *mut key_table,
) -> *mut key_table {
    let mut current_block: u64;
    let mut child: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut parent: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut old: *mut key_table = elm;
    let mut color: i32 = 0;
    if (unsafe { (*elm).entry.rbe_left }).is_null() {
        child = unsafe { (*elm).entry.rbe_right };
        current_block = 7245201122033322888;
    } else if (unsafe { (*elm).entry.rbe_right }).is_null() {
        child = unsafe { (*elm).entry.rbe_left };
        current_block = 7245201122033322888;
    } else {
        let mut left: *mut key_table = std::ptr::null_mut::<key_table>();
        elm = unsafe { (*elm).entry.rbe_right };
        loop {
            left = unsafe { (*elm).entry.rbe_left };
            if left.is_null() {
                break;
            }
            elm = left;
        }
        child = unsafe { (*elm).entry.rbe_right };
        parent = unsafe { (*elm).entry.rbe_parent };
        color = unsafe { (*elm).entry.rbe_color };
        if !child.is_null() {
            (unsafe { (*child).entry.rbe_parent = parent });
        }
        if !parent.is_null() {
            if (unsafe { (*parent).entry.rbe_left }) == elm {
                (unsafe { (*parent).entry.rbe_left = child });
            } else {
                (unsafe { (*parent).entry.rbe_right = child });
            }
        } else {
            (unsafe { (*head).rbh_root = child });
        }
        if (unsafe { (*elm).entry.rbe_parent }) == old {
            parent = elm;
        }
        (unsafe { (*elm).entry = (*old).entry });
        if !(unsafe { (*old).entry.rbe_parent }).is_null() {
            if (unsafe { (*(*old).entry.rbe_parent).entry.rbe_left }) == old {
                (unsafe { (*(*old).entry.rbe_parent).entry.rbe_left = elm });
            } else {
                (unsafe { (*(*old).entry.rbe_parent).entry.rbe_right = elm });
            }
        } else {
            (unsafe { (*head).rbh_root = elm });
        }
        (unsafe { (*(*old).entry.rbe_left).entry.rbe_parent = elm });
        if !(unsafe { (*old).entry.rbe_right }).is_null() {
            (unsafe { (*(*old).entry.rbe_right).entry.rbe_parent = elm });
        }
        if !parent.is_null() {
            left = parent;
            loop {
                left = unsafe { (*left).entry.rbe_parent };
                if left.is_null() {
                    break;
                }
            }
        }
        current_block = 11802870361759373339;
    }
    match current_block {
        7245201122033322888 => {
            parent = unsafe { (*elm).entry.rbe_parent };
            color = unsafe { (*elm).entry.rbe_color };
            if !child.is_null() {
                (unsafe { (*child).entry.rbe_parent = parent });
            }
            if !parent.is_null() {
                if (unsafe { (*parent).entry.rbe_left }) == elm {
                    (unsafe { (*parent).entry.rbe_left = child });
                } else {
                    (unsafe { (*parent).entry.rbe_right = child });
                }
            } else {
                (unsafe { (*head).rbh_root = child });
            }
        }
        _ => {}
    }
    if color == 0 {
        key_tables_RB_REMOVE_COLOR(head, parent, child);
    }
    return old;
}
extern "C" fn key_tables_RB_REMOVE_COLOR(
    mut head: *mut key_tables,
    mut parent: *mut key_table,
    mut elm: *mut key_table,
) {
    let mut tmp: *mut key_table = std::ptr::null_mut::<key_table>();
    while (elm.is_null() || (unsafe { (*elm).entry.rbe_color }) == 0)
        && elm != (unsafe { (*head).rbh_root })
    {
        if (unsafe { (*parent).entry.rbe_left }) == elm {
            tmp = unsafe { (*parent).entry.rbe_right };
            if (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 1 });
                tmp = unsafe { (*parent).entry.rbe_right };
                (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).entry.rbe_right };
            }
            if ((unsafe { (*tmp).entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0
                {
                    let mut oleft: *mut key_table = std::ptr::null_mut::<key_table>();
                    oleft = unsafe { (*tmp).entry.rbe_left };
                    if !oleft.is_null() {
                        (unsafe { (*oleft).entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).entry.rbe_color = 1 });
                    oleft = unsafe { (*tmp).entry.rbe_left };
                    (unsafe { (*tmp).entry.rbe_left = (*oleft).entry.rbe_right });
                    if !(unsafe { (*tmp).entry.rbe_left }).is_null() {
                        (unsafe { (*(*oleft).entry.rbe_right).entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oleft).entry.rbe_parent = (*tmp).entry.rbe_parent });
                    if !(unsafe { (*oleft).entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left = oleft });
                        } else {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_right = oleft });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oleft });
                    }
                    (unsafe { (*oleft).entry.rbe_right = tmp });
                    (unsafe { (*tmp).entry.rbe_parent = oleft });
                    let _ = !(unsafe { (*oleft).entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).entry.rbe_right };
                }
                (unsafe { (*tmp).entry.rbe_color = (*parent).entry.rbe_color });
                (unsafe { (*parent).entry.rbe_color = 0 });
                if !(unsafe { (*tmp).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).entry.rbe_right };
                (unsafe { (*parent).entry.rbe_right = (*tmp).entry.rbe_left });
                if !(unsafe { (*parent).entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_left = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        } else {
            tmp = unsafe { (*parent).entry.rbe_left };
            if (unsafe { (*tmp).entry.rbe_color }) == 1 {
                (unsafe { (*tmp).entry.rbe_color = 0 });
                (unsafe { (*parent).entry.rbe_color = 1 });
                tmp = unsafe { (*parent).entry.rbe_left };
                (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                tmp = unsafe { (*parent).entry.rbe_left };
            }
            if ((unsafe { (*tmp).entry.rbe_left }).is_null()
                || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0)
                && ((unsafe { (*tmp).entry.rbe_right }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_color }) == 0)
            {
                (unsafe { (*tmp).entry.rbe_color = 1 });
                elm = parent;
                parent = unsafe { (*elm).entry.rbe_parent };
            } else {
                if (unsafe { (*tmp).entry.rbe_left }).is_null()
                    || (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color }) == 0
                {
                    let mut oright: *mut key_table = std::ptr::null_mut::<key_table>();
                    oright = unsafe { (*tmp).entry.rbe_right };
                    if !oright.is_null() {
                        (unsafe { (*oright).entry.rbe_color = 0 });
                    }
                    (unsafe { (*tmp).entry.rbe_color = 1 });
                    oright = unsafe { (*tmp).entry.rbe_right };
                    (unsafe { (*tmp).entry.rbe_right = (*oright).entry.rbe_left });
                    if !(unsafe { (*tmp).entry.rbe_right }).is_null() {
                        (unsafe { (*(*oright).entry.rbe_left).entry.rbe_parent = tmp });
                    }
                    (unsafe { (*oright).entry.rbe_parent = (*tmp).entry.rbe_parent });
                    if !(unsafe { (*oright).entry.rbe_parent }).is_null() {
                        if tmp == (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left }) {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_left = oright });
                        } else {
                            (unsafe { (*(*tmp).entry.rbe_parent).entry.rbe_right = oright });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = oright });
                    }
                    (unsafe { (*oright).entry.rbe_left = tmp });
                    (unsafe { (*tmp).entry.rbe_parent = oright });
                    let _ = !(unsafe { (*oright).entry.rbe_parent }).is_null();
                    tmp = unsafe { (*parent).entry.rbe_left };
                }
                (unsafe { (*tmp).entry.rbe_color = (*parent).entry.rbe_color });
                (unsafe { (*parent).entry.rbe_color = 0 });
                if !(unsafe { (*tmp).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_left).entry.rbe_color = 0 });
                }
                tmp = unsafe { (*parent).entry.rbe_left };
                (unsafe { (*parent).entry.rbe_left = (*tmp).entry.rbe_right });
                if !(unsafe { (*parent).entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).entry.rbe_right).entry.rbe_parent = parent });
                }
                (unsafe { (*tmp).entry.rbe_parent = (*parent).entry.rbe_parent });
                if !(unsafe { (*tmp).entry.rbe_parent }).is_null() {
                    if parent == (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left }) {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*parent).entry.rbe_parent).entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).entry.rbe_right = parent });
                (unsafe { (*parent).entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).entry.rbe_parent }).is_null();
                elm = unsafe { (*head).rbh_root };
                break;
            }
        }
    }
    if !elm.is_null() {
        (unsafe { (*elm).entry.rbe_color = 0 });
    }
}
static mut key_tables: key_tables = {
    let mut init = key_tables {
        rbh_root: 0 as *const key_table as *mut key_table,
    };
    init
};
extern "C" fn key_table_cmp(mut table1: *mut key_table, mut table2: *mut key_table) -> i32 {
    return unsafe { strcmp((*table1).name, (*table2).name) };
}
extern "C" fn key_bindings_cmp(mut bd1: *mut key_binding, mut bd2: *mut key_binding) -> i32 {
    if (unsafe { (*bd1).key }) < (unsafe { (*bd2).key }) {
        return -(1 as i32);
    }
    if (unsafe { (*bd1).key }) > (unsafe { (*bd2).key }) {
        return 1;
    }
    return 0;
}
extern "C" fn key_bindings_free(mut bd: *mut key_binding) {
    (unsafe { cmd_list_free((*bd).cmdlist) });
    (unsafe { free((*bd).note as *mut ()) });
    (unsafe { free(bd as *mut ()) });
}
#[no_mangle]
pub extern "C" fn key_bindings_get_table(mut name: *const i8, mut create: i32) -> *mut key_table {
    let mut table_find: key_table = key_table {
        name: std::ptr::null::<i8>(),
        activity_time: timeval {
            tv_sec: 0,
            tv_usec: 0,
        },
        key_bindings: key_bindings {
            rbh_root: std::ptr::null_mut::<key_binding>(),
        },
        default_key_bindings: key_bindings {
            rbh_root: std::ptr::null_mut::<key_binding>(),
        },
        references: 0,
        entry: C2RustUnnamed_28 {
            rbe_left: std::ptr::null_mut::<key_table>(),
            rbe_right: std::ptr::null_mut::<key_table>(),
            rbe_parent: std::ptr::null_mut::<key_table>(),
            rbe_color: 0,
        },
    };
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    table_find.name = name;
    table = key_tables_RB_FIND(unsafe { &mut key_tables }, &mut table_find);
    if !table.is_null() || create == 0 {
        return table;
    }
    table = (unsafe { xmalloc(::core::mem::size_of::<key_table>() as u64) }) as *mut key_table;
    (unsafe { (*table).name = xstrdup(name) });
    (unsafe { (*table).key_bindings.rbh_root = std::ptr::null_mut::<key_binding>() });
    (unsafe { (*table).default_key_bindings.rbh_root = std::ptr::null_mut::<key_binding>() });
    (unsafe { (*table).references = 1 as u_int });
    key_tables_RB_INSERT(unsafe { &mut key_tables }, table);
    return table;
}
#[no_mangle]
pub extern "C" fn key_bindings_first_table() -> *mut key_table {
    return key_tables_RB_MINMAX(unsafe { &mut key_tables }, -(1 as i32));
}
#[no_mangle]
pub extern "C" fn key_bindings_next_table(mut table: *mut key_table) -> *mut key_table {
    return key_tables_RB_NEXT(table);
}
#[no_mangle]
pub extern "C" fn key_bindings_unref_table(mut table: *mut key_table) {
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut bd1: *mut key_binding = std::ptr::null_mut::<key_binding>();
    (unsafe { (*table).references = ((*table).references).wrapping_sub(1) });
    if (unsafe { (*table).references }) != 0 as u32 {
        return;
    }
    bd = key_bindings_RB_MINMAX(unsafe { &mut (*table).key_bindings }, -(1 as i32));
    while !bd.is_null() && {
        bd1 = key_bindings_RB_NEXT(bd); 1 != 0
    } {
        key_bindings_RB_REMOVE(unsafe { &mut (*table).key_bindings }, bd);
        key_bindings_free(bd);
        bd = bd1;
    }
    bd = key_bindings_RB_MINMAX(unsafe { &mut (*table).default_key_bindings }, -(1 as i32));
    while !bd.is_null() && {
        bd1 = key_bindings_RB_NEXT(bd); 1 != 0
    } {
        key_bindings_RB_REMOVE(unsafe { &mut (*table).default_key_bindings }, bd);
        key_bindings_free(bd);
        bd = bd1;
    }
    (unsafe { free((*table).name as *mut ()) });
    (unsafe { free(table as *mut ()) });
}
#[no_mangle]
pub extern "C" fn key_bindings_get(
    mut table: *mut key_table,
    mut key: key_code,
) -> *mut key_binding {
    let mut bd: key_binding = key_binding {
        key: 0,
        cmdlist: std::ptr::null_mut::<cmd_list>(),
        note: std::ptr::null::<i8>(),
        flags: 0,
        entry: C2RustUnnamed_29 {
            rbe_left: std::ptr::null_mut::<key_binding>(),
            rbe_right: std::ptr::null_mut::<key_binding>(),
            rbe_parent: std::ptr::null_mut::<key_binding>(),
            rbe_color: 0,
        },
    };
    bd.key = key;
    return key_bindings_RB_FIND(unsafe { &mut (*table).key_bindings }, &mut bd);
}
#[no_mangle]
pub extern "C" fn key_bindings_get_default(
    mut table: *mut key_table,
    mut key: key_code,
) -> *mut key_binding {
    let mut bd: key_binding = key_binding {
        key: 0,
        cmdlist: std::ptr::null_mut::<cmd_list>(),
        note: std::ptr::null::<i8>(),
        flags: 0,
        entry: C2RustUnnamed_29 {
            rbe_left: std::ptr::null_mut::<key_binding>(),
            rbe_right: std::ptr::null_mut::<key_binding>(),
            rbe_parent: std::ptr::null_mut::<key_binding>(),
            rbe_color: 0,
        },
    };
    bd.key = key;
    return key_bindings_RB_FIND(unsafe { &mut (*table).default_key_bindings }, &mut bd);
}
#[no_mangle]
pub extern "C" fn key_bindings_first(mut table: *mut key_table) -> *mut key_binding {
    return key_bindings_RB_MINMAX(unsafe { &mut (*table).key_bindings }, -(1 as i32));
}
#[no_mangle]
pub extern "C" fn key_bindings_next(
    mut _table: *mut key_table,
    mut bd: *mut key_binding,
) -> *mut key_binding {
    return key_bindings_RB_NEXT(bd);
}
#[no_mangle]
pub extern "C" fn key_bindings_add(
    mut name: *const i8,
    mut key: key_code,
    mut note: *const i8,
    mut repeat: i32,
    mut cmdlist: *mut cmd_list,
) {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut s: *mut i8 = std::ptr::null_mut::<i8>();
    table = key_bindings_get_table(name, 1);
    bd = key_bindings_get(table, key & !(KEYC_MASK_FLAGS000000 as u64));
    if cmdlist.is_null() {
        if !bd.is_null() {
            (unsafe { free((*bd).note as *mut ()) });
            if !note.is_null() {
                (unsafe { (*bd).note = xstrdup(note) });
            } else {
                (unsafe { (*bd).note = std::ptr::null::<i8>() });
            }
        }
        return;
    }
    if !bd.is_null() {
        key_bindings_RB_REMOVE(unsafe { &mut (*table).key_bindings }, bd);
        key_bindings_free(bd);
    }
    bd = (unsafe {
        xcalloc( 1 as size_t,
            ::core::mem::size_of::<key_binding>() as u64,
        )
    }) as *mut key_binding;
    (unsafe { (*bd).key = key & !(KEYC_MASK_FLAGS000000 as u64) });
    if !note.is_null() {
        (unsafe { (*bd).note = xstrdup(note) });
    }
    key_bindings_RB_INSERT(unsafe { &mut (*table).key_bindings }, bd);
    if repeat != 0 {
        (unsafe { (*bd).flags |= 0x1 as i32 });
    }
    (unsafe { (*bd).cmdlist = cmdlist });
    s = unsafe { cmd_list_print((*bd).cmdlist, 0) };
    (unsafe {
        log_debug(
            b"%s: %#llx %s = %s\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 17], &[i8; 17]>(b"key_bindings_add\0")).as_ptr(),
            (*bd).key,
            key_string_lookup_key((*bd).key, 1),
            s,
        )
    });
    (unsafe { free(s as *mut ()) });
}
#[no_mangle]
pub extern "C" fn key_bindings_remove(mut name: *const i8, mut key: key_code) {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    table = key_bindings_get_table(name, 0);
    if table.is_null() {
        return;
    }
    bd = key_bindings_get(table, key & !(KEYC_MASK_FLAGS000000 as u64));
    if bd.is_null() {
        return;
    }
    (unsafe {
        log_debug(
            b"%s: %#llx %s\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 20], &[i8; 20]>(b"key_bindings_remove\0")).as_ptr(),
            (*bd).key,
            key_string_lookup_key((*bd).key, 1),
        )
    });
    key_bindings_RB_REMOVE(unsafe { &mut (*table).key_bindings }, bd);
    key_bindings_free(bd);
    if (unsafe { (*table).key_bindings.rbh_root }).is_null()
        && (unsafe { (*table).default_key_bindings.rbh_root }).is_null()
    {
        key_tables_RB_REMOVE(unsafe { &mut key_tables }, table);
        key_bindings_unref_table(table);
    }
}
#[no_mangle]
pub extern "C" fn key_bindings_reset(mut name: *const i8, mut key: key_code) {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut dd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    table = key_bindings_get_table(name, 0);
    if table.is_null() {
        return;
    }
    bd = key_bindings_get(table, key & !(KEYC_MASK_FLAGS000000 as u64));
    if bd.is_null() {
        return;
    }
    dd = key_bindings_get_default(table, unsafe { (*bd).key });
    if dd.is_null() {
        key_bindings_remove(name, unsafe { (*bd).key });
        return;
    }
    (unsafe { cmd_list_free((*bd).cmdlist) });
    (unsafe { (*bd).cmdlist = (*dd).cmdlist });
    (unsafe { (*(*bd).cmdlist).references += 1 });
    (unsafe { free((*bd).note as *mut ()) });
    if !(unsafe { (*dd).note }).is_null() {
        (unsafe { (*bd).note = xstrdup((*dd).note) });
    } else {
        (unsafe { (*bd).note = std::ptr::null::<i8>() });
    }
    (unsafe { (*bd).flags = (*dd).flags });
}
#[no_mangle]
pub extern "C" fn key_bindings_remove_table(mut name: *const i8) {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut c: *mut client = std::ptr::null_mut::<client>();
    table = key_bindings_get_table(name, 0);
    if !table.is_null() {
        key_tables_RB_REMOVE(unsafe { &mut key_tables }, table);
        key_bindings_unref_table(table);
    }
    c = unsafe { clients.tqh_first };
    while !c.is_null() {
        if (unsafe { (*c).keytable }) == table {
            (unsafe { server_client_set_key_table(c, std::ptr::null::<i8>()) });
        }
        c = unsafe { (*c).entry.tqe_next };
    }
}
#[no_mangle]
pub extern "C" fn key_bindings_reset_table(mut name: *const i8) {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut bd1: *mut key_binding = std::ptr::null_mut::<key_binding>();
    table = key_bindings_get_table(name, 0);
    if table.is_null() {
        return;
    }
    if (unsafe { (*table).default_key_bindings.rbh_root }).is_null() {
        key_bindings_remove_table(name);
        return;
    }
    bd = key_bindings_RB_MINMAX(unsafe { &mut (*table).key_bindings }, -(1 as i32));
    while !bd.is_null() && {
        bd1 = key_bindings_RB_NEXT(bd); 1 != 0
    } {
        key_bindings_reset(name, unsafe { (*bd).key });
        bd = bd1;
    }
}
extern "C" fn key_bindings_init_done(
    mut _item: *mut cmdq_item,
    mut _data: *mut (),
) -> cmd_retval {
    let mut table: *mut key_table = std::ptr::null_mut::<key_table>();
    let mut bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    let mut new_bd: *mut key_binding = std::ptr::null_mut::<key_binding>();
    table = key_tables_RB_MINMAX(unsafe { &mut key_tables }, -(1 as i32));
    while !table.is_null() {
        bd = key_bindings_RB_MINMAX(unsafe { &mut (*table).key_bindings }, -(1 as i32));
        while !bd.is_null() {
            new_bd = (unsafe {
                xcalloc( 1 as size_t,
                    ::core::mem::size_of::<key_binding>() as u64,
                )
            }) as *mut key_binding;
            (unsafe { (*new_bd).key = (*bd).key });
            if !(unsafe { (*bd).note }).is_null() {
                (unsafe { (*new_bd).note = xstrdup((*bd).note) });
            }
            (unsafe { (*new_bd).flags = (*bd).flags });
            (unsafe { (*new_bd).cmdlist = (*bd).cmdlist });
            (unsafe { (*(*new_bd).cmdlist).references += 1 });
            key_bindings_RB_INSERT(unsafe { &mut (*table).default_key_bindings }, new_bd);
            bd = key_bindings_RB_NEXT(bd);
        }
        table = key_tables_RB_NEXT(table);
    }
    return CMD_RETURN_NORMAL;
}
#[no_mangle]
pub extern "C" fn key_bindings_init() {
    static mut defaults : [* const i8 ; 265] = [b"bind -N 'Send the prefix key' C-b { send-prefix }\0" as * const u8 as * const i8 , b"bind -N 'Rotate through the panes' C-o { rotate-window }\0" as * const u8 as * const i8 , b"bind -N 'Suspend the current client' C-z { suspend-client }\0" as * const u8 as * const i8 , b"bind -N 'Select next layout' Space { next-layout }\0" as * const u8 as * const i8 , b"bind -N 'Break pane to a new window' ! { break-pane }\0" as * const u8 as * const i8 , b"bind -N 'Split window vertically' '\"' { split-window }\0" as * const u8 as * const i8 , b"bind -N 'List all paste buffers' '#' { list-buffers }\0" as * const u8 as * const i8 , b"bind -N 'Rename current session' '$' { command-prompt -I'#S' { rename-session -- '%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Split window horizontally' % { split-window -h }\0" as * const u8 as * const i8 , b"bind -N 'Kill current window' & { confirm-before -p\"kill-window #W? (y/n)\" kill-window }\0" as * const u8 as * const i8 , b"bind -N 'Prompt for window index to select' \"'\" { command-prompt -T window-target -pindex { select-window -t ':%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Switch to previous client' ( { switch-client -p }\0" as * const u8 as * const i8 , b"bind -N 'Switch to next client' ) { switch-client -n }\0" as * const u8 as * const i8 , b"bind -N 'Rename current window' , { command-prompt -I'#W' { rename-window -- '%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Delete the most recent paste buffer' - { delete-buffer }\0" as * const u8 as * const i8 , b"bind -N 'Move the current window' . { command-prompt -T target { move-window -t '%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Describe key binding' '/' { command-prompt -kpkey  { list-keys -1N '%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Select window 0' 0 { select-window -t:=0 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 1' 1 { select-window -t:=1 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 2' 2 { select-window -t:=2 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 3' 3 { select-window -t:=3 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 4' 4 { select-window -t:=4 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 5' 5 { select-window -t:=5 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 6' 6 { select-window -t:=6 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 7' 7 { select-window -t:=7 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 8' 8 { select-window -t:=8 }\0" as * const u8 as * const i8 , b"bind -N 'Select window 9' 9 { select-window -t:=9 }\0" as * const u8 as * const i8 , b"bind -N 'Prompt for a command' : { command-prompt }\0" as * const u8 as * const i8 , b"bind -N 'Move to the previously active pane' \\; { last-pane }\0" as * const u8 as * const i8 , b"bind -N 'Choose a paste buffer from a list' = { choose-buffer -Z }\0" as * const u8 as * const i8 , b"bind -N 'List key bindings' ? { list-keys -N }\0" as * const u8 as * const i8 , b"bind -N 'Choose and detach a client from a list' D { choose-client -Z }\0" as * const u8 as * const i8 , b"bind -N 'Spread panes out evenly' E { select-layout -E }\0" as * const u8 as * const i8 , b"bind -N 'Switch to the last client' L { switch-client -l }\0" as * const u8 as * const i8 , b"bind -N 'Clear the marked pane' M { select-pane -M }\0" as * const u8 as * const i8 , b"bind -N 'Enter copy mode' [ { copy-mode }\0" as * const u8 as * const i8 , b"bind -N 'Paste the most recent paste buffer' ] { paste-buffer -p }\0" as * const u8 as * const i8 , b"bind -N 'Create a new window' c { new-window }\0" as * const u8 as * const i8 , b"bind -N 'Detach the current client' d { detach-client }\0" as * const u8 as * const i8 , b"bind -N 'Search for a pane' f { command-prompt { find-window -Z -- '%%' } }\0" as * const u8 as * const i8 , b"bind -N 'Display window information' i { display-message }\0" as * const u8 as * const i8 , b"bind -N 'Select the previously current window' l { last-window }\0" as * const u8 as * const i8 , b"bind -N 'Toggle the marked pane' m { select-pane -m }\0" as * const u8 as * const i8 , b"bind -N 'Select the next window' n { next-window }\0" as * const u8 as * const i8 , b"bind -N 'Select the next pane' o { select-pane -t:.+ }\0" as * const u8 as * const i8 , b"bind -N 'Customize options' C { customize-mode -Z }\0" as * const u8 as * const i8 , b"bind -N 'Select the previous window' p { previous-window }\0" as * const u8 as * const i8 , b"bind -N 'Display pane numbers' q { display-panes }\0" as * const u8 as * const i8 , b"bind -N 'Redraw the current client' r { refresh-client }\0" as * const u8 as * const i8 , b"bind -N 'Choose a session from a list' s { choose-tree -Zs }\0" as * const u8 as * const i8 , b"bind -N 'Show a clock' t { clock-mode }\0" as * const u8 as * const i8 , b"bind -N 'Choose a window from a list' w { choose-tree -Zw }\0" as * const u8 as * const i8 , b"bind -N 'Kill the active pane' x { confirm-before -p\"kill-pane #P? (y/n)\" kill-pane }\0" as * const u8 as * const i8 , b"bind -N 'Zoom the active pane' z { resize-pane -Z }\0" as * const u8 as * const i8 , b"bind -N 'Swap the active pane with the pane above' '{' { swap-pane -U }\0" as * const u8 as * const i8 , b"bind -N 'Swap the active pane with the pane below' '}' { swap-pane -D }\0" as * const u8 as * const i8 , b"bind -N 'Show messages' '~' { show-messages }\0" as * const u8 as * const i8 , b"bind -N 'Enter copy mode and scroll up' PPage { copy-mode -u }\0" as * const u8 as * const i8 , b"bind -N 'Select the pane above the active pane' -r Up { select-pane -U }\0" as * const u8 as * const i8 , b"bind -N 'Select the pane below the active pane' -r Down { select-pane -D }\0" as * const u8 as * const i8 , b"bind -N 'Select the pane to the left of the active pane' -r Left { select-pane -L }\0" as * const u8 as * const i8 , b"bind -N 'Select the pane to the right of the active pane' -r Right { select-pane -R }\0" as * const u8 as * const i8 , b"bind -N 'Set the even-horizontal layout' M-1 { select-layout even-horizontal }\0" as * const u8 as * const i8 , b"bind -N 'Set the even-vertical layout' M-2 { select-layout even-vertical }\0" as * const u8 as * const i8 , b"bind -N 'Set the main-horizontal layout' M-3 { select-layout main-horizontal }\0" as * const u8 as * const i8 , b"bind -N 'Set the main-vertical layout' M-4 { select-layout main-vertical }\0" as * const u8 as * const i8 , b"bind -N 'Select the tiled layout' M-5 { select-layout tiled }\0" as * const u8 as * const i8 , b"bind -N 'Set the main-horizontal-mirrored layout' M-6 { select-layout main-horizontal-mirrored }\0" as * const u8 as * const i8 , b"bind -N 'Set the main-vertical-mirrored layout' M-7 { select-layout main-vertical-mirrored }\0" as * const u8 as * const i8 , b"bind -N 'Select the next window with an alert' M-n { next-window -a }\0" as * const u8 as * const i8 , b"bind -N 'Rotate through the panes in reverse' M-o { rotate-window -D }\0" as * const u8 as * const i8 , b"bind -N 'Select the previous window with an alert' M-p { previous-window -a }\0" as * const u8 as * const i8 , b"bind -N 'Move the visible part of the window up' -r S-Up { refresh-client -U 10 }\0" as * const u8 as * const i8 , b"bind -N 'Move the visible part of the window down' -r S-Down { refresh-client -D 10 }\0" as * const u8 as * const i8 , b"bind -N 'Move the visible part of the window left' -r S-Left { refresh-client -L 10 }\0" as * const u8 as * const i8 , b"bind -N 'Move the visible part of the window right' -r S-Right { refresh-client -R 10 }\0" as * const u8 as * const i8 , b"bind -N 'Reset so the visible part of the window follows the cursor' -r DC { refresh-client -c }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane up by 5' -r M-Up { resize-pane -U 5 }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane down by 5' -r M-Down { resize-pane -D 5 }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane left by 5' -r M-Left { resize-pane -L 5 }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane right by 5' -r M-Right { resize-pane -R 5 }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane up' -r C-Up { resize-pane -U }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane down' -r C-Down { resize-pane -D }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane left' -r C-Left { resize-pane -L }\0" as * const u8 as * const i8 , b"bind -N 'Resize the pane right' -r C-Right { resize-pane -R }\0" as * const u8 as * const i8 , b"bind < { display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}'  '#{?#{>:#{session_windows},1},,-}Swap Left' 'l' {swap-window -t:-1} '#{?#{>:#{session_windows},1},,-}Swap Right' 'r' {swap-window -t:+1} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window} '' 'Kill' 'X' {kill-window} 'Respawn' 'R' {respawn-window -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} 'Rename' 'n' {command-prompt -FI \"#W\" {rename-window -t '#{window_id}' -- '%%'}} '' 'New After' 'w' {new-window -a} 'New At End' 'W' {new-window} }\0" as * const u8 as * const i8 , b"bind > { display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})'  '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top} '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom} '' '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward -- \"#{q:mouse_word}\"} '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"} '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"} '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"} '' '#{?mouse_hyperlink,Type #[underscore]#{=/9/...:mouse_hyperlink},}' 'C-h' {copy-mode -q; send-keys -l -- \"#{q:mouse_hyperlink}\"} '#{?mouse_hyperlink,Copy #[underscore]#{=/9/...:mouse_hyperlink},}' 'h' {copy-mode -q; set-buffer -- \"#{q:mouse_hyperlink}\"} '' 'Horizontal Split' 'h' {split-window -h} 'Vertical Split' 'v' {split-window -v} '' '#{?#{>:#{window_panes},1},,-}Swap Up' 'u' {swap-pane -U} '#{?#{>:#{window_panes},1},,-}Swap Down' 'd' {swap-pane -D} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane} '' 'Kill' 'X' {kill-pane} 'Respawn' 'R' {respawn-pane -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} '#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z} }\0" as * const u8 as * const i8 , b"bind -n MouseDown1Pane { select-pane -t=; send -M }\0" as * const u8 as * const i8 , b"bind -n MouseDrag1Pane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M } }\0" as * const u8 as * const i8 , b"bind -n WheelUpPane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e } }\0" as * const u8 as * const i8 , b"bind -n MouseDown2Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p } }\0" as * const u8 as * const i8 , b"bind -n DoubleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel } }\0" as * const u8 as * const i8 , b"bind -n TripleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel } }\0" as * const u8 as * const i8 , b"bind -n MouseDrag1Border { resize-pane -M }\0" as * const u8 as * const i8 , b"bind -n MouseDown1Status { select-window -t= }\0" as * const u8 as * const i8 , b"bind -n WheelDownStatus { next-window }\0" as * const u8 as * const i8 , b"bind -n WheelUpStatus { previous-window }\0" as * const u8 as * const i8 , b"bind -n MouseDown3StatusLeft { display-menu -t= -xM -yW -T '#[align=centre]#{session_name}'  'Next' 'n' {switch-client -n} 'Previous' 'p' {switch-client -p} '' 'Renumber' 'N' {move-window -r} 'Rename' 'n' {command-prompt -I \"#S\" {rename-session -- '%%'}} '' 'New Session' 's' {new-session} 'New Window' 'w' {new-window} }\0" as * const u8 as * const i8 , b"bind -n M-MouseDown3StatusLeft { display-menu -t= -xM -yW -T '#[align=centre]#{session_name}'  'Next' 'n' {switch-client -n} 'Previous' 'p' {switch-client -p} '' 'Renumber' 'N' {move-window -r} 'Rename' 'n' {command-prompt -I \"#S\" {rename-session -- '%%'}} '' 'New Session' 's' {new-session} 'New Window' 'w' {new-window} }\0" as * const u8 as * const i8 , b"bind -n MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}'  '#{?#{>:#{session_windows},1},,-}Swap Left' 'l' {swap-window -t:-1} '#{?#{>:#{session_windows},1},,-}Swap Right' 'r' {swap-window -t:+1} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window} '' 'Kill' 'X' {kill-window} 'Respawn' 'R' {respawn-window -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} 'Rename' 'n' {command-prompt -FI \"#W\" {rename-window -t '#{window_id}' -- '%%'}} '' 'New After' 'w' {new-window -a} 'New At End' 'W' {new-window}}\0" as * const u8 as * const i8 , b"bind -n M-MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}'  '#{?#{>:#{session_windows},1},,-}Swap Left' 'l' {swap-window -t:-1} '#{?#{>:#{session_windows},1},,-}Swap Right' 'r' {swap-window -t:+1} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window} '' 'Kill' 'X' {kill-window} 'Respawn' 'R' {respawn-window -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} 'Rename' 'n' {command-prompt -FI \"#W\" {rename-window -t '#{window_id}' -- '%%'}} '' 'New After' 'w' {new-window -a} 'New At End' 'W' {new-window}}\0" as * const u8 as * const i8 , b"bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})'  '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top} '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom} '' '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward -- \"#{q:mouse_word}\"} '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"} '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"} '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"} '' '#{?mouse_hyperlink,Type #[underscore]#{=/9/...:mouse_hyperlink},}' 'C-h' {copy-mode -q; send-keys -l -- \"#{q:mouse_hyperlink}\"} '#{?mouse_hyperlink,Copy #[underscore]#{=/9/...:mouse_hyperlink},}' 'h' {copy-mode -q; set-buffer -- \"#{q:mouse_hyperlink}\"} '' 'Horizontal Split' 'h' {split-window -h} 'Vertical Split' 'v' {split-window -v} '' '#{?#{>:#{window_panes},1},,-}Swap Up' 'u' {swap-pane -U} '#{?#{>:#{window_panes},1},,-}Swap Down' 'd' {swap-pane -D} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane} '' 'Kill' 'X' {kill-pane} 'Respawn' 'R' {respawn-pane -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} '#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z} } }\0" as * const u8 as * const i8 , b"bind -n M-MouseDown3Pane { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})'  '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top} '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom} '' '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward -- \"#{q:mouse_word}\"} '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"} '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"} '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"} '' '#{?mouse_hyperlink,Type #[underscore]#{=/9/...:mouse_hyperlink},}' 'C-h' {copy-mode -q; send-keys -l -- \"#{q:mouse_hyperlink}\"} '#{?mouse_hyperlink,Copy #[underscore]#{=/9/...:mouse_hyperlink},}' 'h' {copy-mode -q; set-buffer -- \"#{q:mouse_hyperlink}\"} '' 'Horizontal Split' 'h' {split-window -h} 'Vertical Split' 'v' {split-window -v} '' '#{?#{>:#{window_panes},1},,-}Swap Up' 'u' {swap-pane -U} '#{?#{>:#{window_panes},1},,-}Swap Down' 'd' {swap-pane -D} '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane} '' 'Kill' 'X' {kill-pane} 'Respawn' 'R' {respawn-pane -k} '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m} '#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z} }\0" as * const u8 as * const i8 , b"bind -n MouseDown1ScrollbarUp { copy-mode -u }\0" as * const u8 as * const i8 , b"bind -n MouseDown1ScrollbarDown { copy-mode -d }\0" as * const u8 as * const i8 , b"bind -n MouseDrag1ScrollbarSlider { copy-mode -S }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-Space { send -X begin-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-a { send -X start-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-c { send -X cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-e { send -X end-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-f { send -X cursor-right }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-b { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-g { send -X clear-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-k { send -X copy-pipe-end-of-line-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-n { send -X cursor-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-p { send -X cursor-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-r { command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-s { command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-v { send -X page-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Escape { send -X cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Space { send -X page-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode , { send -X jump-reverse }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode \\; { send -X jump-again }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode F { command-prompt -1p'(jump backward)' { send -X jump-backward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode N { send -X search-reverse }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode P { send -X toggle-position }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode R { send -X rectangle-toggle }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode X { send -X set-mark }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode f { command-prompt -1p'(jump forward)' { send -X jump-forward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode g { command-prompt -p'(goto line)' { send -X goto-line -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode n { send -X search-again }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode q { send -X cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode r { send -X refresh-from-pane }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Home { send -X start-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode End { send -X end-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode MouseDown1Pane select-pane\0" as * const u8 as * const i8 , b"bind -Tcopy-mode MouseDrag1Pane { select-pane; send -X begin-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode MouseDragEnd1Pane { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode WheelUpPane { select-pane; send -N5 -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode WheelDownPane { select-pane; send -N5 -X scroll-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode NPage { send -X page-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode PPage { send -X page-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Up { send -X cursor-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Down { send -X cursor-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Left { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode Right { send -X cursor-right }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-3 { command-prompt -Np'(repeat)' -I3 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-4 { command-prompt -Np'(repeat)' -I4 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-5 { command-prompt -Np'(repeat)' -I5 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-6 { command-prompt -Np'(repeat)' -I6 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-< { send -X history-top }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-> { send -X history-bottom }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-R { send -X top-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-b { send -X previous-word }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-M-b { send -X previous-matching-bracket }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-f { send -X next-word-end }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-M-f { send -X next-matching-bracket }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-m { send -X back-to-indentation }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-r { send -X middle-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-v { send -X page-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-w { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-x { send -X jump-to-mark }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode 'M-{' { send -X previous-paragraph }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode 'M-}' { send -X next-paragraph }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-Up { send -X halfpage-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode M-Down { send -X halfpage-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-Up { send -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode C-Down { send -X scroll-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi '#' { send -FX search-backward -- '#{copy_cursor_word}' }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi * { send -FX search-forward -- '#{copy_cursor_word}' }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-c { send -X cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-d { send -X halfpage-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-e { send -X scroll-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-b { send -X page-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-f { send -X page-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-h { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-j { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Enter { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-u { send -X halfpage-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-v { send -X rectangle-toggle }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-y { send -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Escape { send -X clear-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Space { send -X begin-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi '$' { send -X end-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi , { send -X jump-reverse }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi / { command-prompt -T search -p'(search down)' { send -X search-forward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 0 { send -X start-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 3 { command-prompt -Np'(repeat)' -I3 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 4 { command-prompt -Np'(repeat)' -I4 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 5 { command-prompt -Np'(repeat)' -I5 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 6 { command-prompt -Np'(repeat)' -I6 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi 9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi : { command-prompt -p'(goto line)' { send -X goto-line -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi \\; { send -X jump-again }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi ? { command-prompt -T search -p'(search up)' { send -X search-backward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi A { send -X append-selection-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi B { send -X previous-space }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi D { send -X copy-pipe-end-of-line-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi E { send -X next-space-end }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi F { command-prompt -1p'(jump backward)' { send -X jump-backward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi G { send -X history-bottom }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi H { send -X top-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi J { send -X scroll-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi K { send -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi L { send -X bottom-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi M { send -X middle-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi N { send -X search-reverse }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi P { send -X toggle-position }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi V { send -X select-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi W { send -X next-space }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi X { send -X set-mark }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi ^ { send -X back-to-indentation }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi b { send -X previous-word }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi e { send -X next-word-end }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi f { command-prompt -1p'(jump forward)' { send -X jump-forward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi g { send -X history-top }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi h { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi j { send -X cursor-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi k { send -X cursor-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi z { send -X scroll-middle }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi l { send -X cursor-right }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi n { send -X search-again }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi o { send -X other-end }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi q { send -X cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi r { send -X refresh-from-pane }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi v { send -X rectangle-toggle }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi w { send -X next-word }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi '{' { send -X previous-paragraph }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi '}' { send -X next-paragraph }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi % { send -X next-matching-bracket }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Home { send -X start-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi End { send -X end-of-line }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi MouseDown1Pane { select-pane }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi MouseDrag1Pane { select-pane; send -X begin-selection }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi MouseDragEnd1Pane { send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi WheelUpPane { select-pane; send -N5 -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi WheelDownPane { select-pane; send -N5 -X scroll-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi BSpace { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi NPage { send -X page-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi PPage { send -X page-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Up { send -X cursor-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Down { send -X cursor-down }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Left { send -X cursor-left }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi Right { send -X cursor-right }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi M-x { send -X jump-to-mark }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-Up { send -X scroll-up }\0" as * const u8 as * const i8 , b"bind -Tcopy-mode-vi C-Down { send -X scroll-down }\0" as * const u8 as * const i8 ,] ;
    let mut i: u_int = 0;
    let mut pr: *mut cmd_parse_result = std::ptr::null_mut::<cmd_parse_result>();
    i = 0 as u_int;
    while (i as u64)
        < (::core::mem::size_of::<[*const i8; 265]>() as u64)
            .wrapping_div(::core::mem::size_of::<*const i8>() as u64)
    {
        pr = unsafe {
            cmd_parse_from_string(
                defaults[i as usize],
                std::ptr::null_mut::<cmd_parse_input>(),
            )
        };
        if (unsafe { (*pr).status }) as u32 != CMD_PARSE_SUCCESS as i32 as u32 {
            (unsafe { log_debug(b"%s\0" as *const u8 as *const i8, (*pr).error) });
            (unsafe {
                fatalx(
                    b"bad default key: %s\0" as *const u8 as *const i8,
                    defaults[i as usize],
                )
            });
        }
        (unsafe {
            cmdq_append(
                std::ptr::null_mut::<client>(),
                cmdq_get_command((*pr).cmdlist, std::ptr::null_mut::<cmdq_state>()),
            )
        });
        (unsafe { cmd_list_free((*pr).cmdlist) });
        i = i.wrapping_add(1);
    }
    (unsafe {
        cmdq_append(
            std::ptr::null_mut::<client>(),
            cmdq_get_callback1(
                b"key_bindings_init_done\0" as *const u8 as *const i8,
                Some(
                    key_bindings_init_done
                        as unsafe extern "C" fn(*mut cmdq_item, *mut ()) -> cmd_retval,
                ),
                std::ptr::null_mut::<()>(),
            ),
        )
    });
}
extern "C" fn key_bindings_read_only(
    mut item: *mut cmdq_item,
    mut _data: *mut (),
) -> cmd_retval {
    (unsafe { cmdq_error(item, b"client is read-only\0" as *const u8 as *const i8) });
    return CMD_RETURN_ERROR;
}
#[no_mangle]
pub extern "C" fn key_bindings_dispatch(
    mut bd: *mut key_binding,
    mut item: *mut cmdq_item,
    mut c: *mut client,
    mut event: *mut key_event,
    mut fs: *mut cmd_find_state,
) -> *mut cmdq_item {
    let mut new_item: *mut cmdq_item = std::ptr::null_mut::<cmdq_item>();
    let mut new_state: *mut cmdq_state = std::ptr::null_mut::<cmdq_state>();
    let mut readonly: i32 = 0;
    let mut flags: i32 = 0;
    if c.is_null() || !(unsafe { (*c).flags }) & 0x800 as i32 as u64 != 0 {
        readonly = 1;
    } else {
        readonly = unsafe { cmd_list_all_have((*bd).cmdlist, 0x2 as i32) };
    }
    if readonly == 0 {
        new_item = unsafe {
            cmdq_get_callback1(
                b"key_bindings_read_only\0" as *const u8 as *const i8,
                Some(
                    key_bindings_read_only
                        as unsafe extern "C" fn(*mut cmdq_item, *mut ()) -> cmd_retval,
                ),
                std::ptr::null_mut::<()>(),
            )
        };
    } else {
        if (unsafe { (*bd).flags }) & 0x1 as i32 != 0 {
            flags |= 0x1 as i32;
        }
        new_state = unsafe { cmdq_new_state(fs, event, flags) };
        new_item = unsafe { cmdq_get_command((*bd).cmdlist, new_state) };
        (unsafe { cmdq_free_state(new_state) });
    }
    if !item.is_null() {
        new_item = unsafe { cmdq_insert_after(item, new_item) };
    } else {
        new_item = unsafe { cmdq_append(c, new_item) };
    }
    return new_item;
}
